package com.rzj.sys_lab_assistant.service.impl;

import com.rzj.sys_lab_assistant.dao.LabMapper;
import com.rzj.sys_lab_assistant.entity.Lab;
import com.rzj.sys_lab_assistant.entity.bo.LabBO;
import com.rzj.sys_lab_assistant.service.ILabService;
import com.rzj.sys_lab_assistant.utils.TimeUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @program: sys_lab_assistant
 * @description:
 * @author: 作者
 * @create: 2021-06-29 12:02
 */
@Service
public class LabServiceImpl implements ILabService {

    @Autowired
    LabMapper labMapper;

    TimeUtils timeUtils;

    @Override
    public List<LabBO> listLabs() {
        return labMapper.listLabs();
    }

    @Override
    public List<LabBO> listLabsByAccount(String account) {
        return labMapper.listLabsByAccount(account);
    }

    @Override
    public LabBO getLabById(int labId) {
        return labMapper.getLabById(labId);
    }

    @Override
    public int addLab(Lab lab) {
        lab.setCreateTime(timeUtils.getTime());
        lab.setModifyTime(timeUtils.getTime());
        int flag = labMapper.saveLab(lab);
        if (flag == 1) {
            // 获取添加完成的实验室id 添加关联表。。
            int labId = labMapper.getLabByName(lab.getLabName()).getLabId();
            System.out.println("labId=>"+labId);
            lab.setLabId(labId);
            System.out.println("lab=>"+lab.toString());
            int i = labMapper.saveLabTechnician(lab);
            if (i == 1) {
                return 1;
            }
        }
        return 0;
    }

    @Override
    public int addLabTechnician(Lab lab) {
        lab.setCreateTime(timeUtils.getTime());
        lab.setModifyTime(timeUtils.getTime());
        return labMapper.saveLabTechnician(lab);
    }

    @Override
    public int editLab(Lab lab) {
        lab.setModifyTime(timeUtils.getTime());
        return labMapper.updateLab(lab);
    }

    @Override
    public int delLab(int labId) {
        return labMapper.deleteLab(labId);
    }
}
